From 3197a62dafeeb1e4f912a6f45bec8e24bdb98111 Mon Sep 17 00:00:00 2001 From: "kfraser@localhost.localdomain" Date: Wed, 13 Dec 2006 11:01:33 +0000 Subject: [PATCH] [IOEMU] Locking needed to access mapcache. Signed-off-by: Keir Fraser --- tools/ioemu/target-i386-dm/exec-dm.c | 11 ++++++++++- tools/ioemu/vl.c | 7 +++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/tools/ioemu/target-i386-dm/exec-dm.c b/tools/ioemu/target-i386-dm/exec-dm.c index 755d547772..08911564a1 100644 --- a/tools/ioemu/target-i386-dm/exec-dm.c +++ b/tools/ioemu/target-i386-dm/exec-dm.c @@ -439,7 +439,12 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf, int l, io_index; uint8_t *ptr; uint32_t val; - + +#if defined(__i386__) || defined(__x86_64__) + static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; + pthread_mutex_lock(&mutex); +#endif + while (len > 0) { /* How much can we copy before the next page boundary? */ l = TARGET_PAGE_SIZE - (addr & ~TARGET_PAGE_MASK); @@ -504,6 +509,10 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf, buf += l; addr += l; } + +#if defined(__i386__) || defined(__x86_64__) + pthread_mutex_unlock(&mutex); +#endif } #endif diff --git a/tools/ioemu/vl.c b/tools/ioemu/vl.c index e14e6a1d9e..6fc10c8187 100644 --- a/tools/ioemu/vl.c +++ b/tools/ioemu/vl.c @@ -5820,8 +5820,8 @@ static int qemu_map_cache_init(unsigned long nr_pages) if (nr_pages < max_pages) max_pages = nr_pages; - nr_buckets = (max_pages << PAGE_SHIFT) >> MCACHE_BUCKET_SHIFT; - + nr_buckets = max_pages + (1UL << (MCACHE_BUCKET_SHIFT - PAGE_SHIFT)) - 1; + nr_buckets >>= (MCACHE_BUCKET_SHIFT - PAGE_SHIFT); fprintf(logfile, "qemu_map_cache_init nr_buckets = %lx\n", nr_buckets); mapcache_entry = malloc(nr_buckets * sizeof(struct map_cache)); @@ -5857,8 +5857,7 @@ uint8_t *qemu_map_cache(target_phys_addr_t phys_addr) entry = &mapcache_entry[address_index % nr_buckets]; - if (entry->vaddr_base == NULL || entry->paddr_index != address_index) - { + if (entry->vaddr_base == NULL || entry->paddr_index != address_index) { /* We need to remap a bucket. */ uint8_t *vaddr_base; unsigned long pfns[MCACHE_BUCKET_SIZE >> PAGE_SHIFT]; -- 2.30.2